package com.zengge.zbc.po;


import com.zengge.zbc.utils.SnowFlakeIdGenerator;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import java.util.Date;

@Table(name = "user_info",indexes = {
        @Index(name = "idx_user_id",columnList = "user_id",unique = true)
})
public class UserInfo {


    @Id
    @Column(name = "object_id")
    private long objectId;

    @Column(name = "user_id")
    private String userId;

    @Column(name = "union_id")
    private String unionId;

    @Column(name = "session_key")
    private String sessionKey;

    @Column(name = "create_time")
    private Date createTime;

    @Column(name = "update_time")
    private Date updateTime;

    public UserInfo() {
    }

    public UserInfo(String userId, String unionId, String sessionKey) {
        this.objectId = SnowFlakeIdGenerator.next();
        this.userId = userId;
        this.unionId = unionId;
        this.sessionKey = sessionKey;
        this.createTime = new Date();
        this.updateTime = new Date();
    }

    public void update(String sessionKey){
        this.sessionKey = sessionKey;
        this.updateTime = new Date();
    }

    public long getObjectId() {
        return objectId;
    }

    public void setObjectId(long objectId) {
        this.objectId = objectId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUnionId() {
        return unionId;
    }

    public void setUnionId(String unionId) {
        this.unionId = unionId;
    }

    public String getSessionKey() {
        return sessionKey;
    }

    public void setSessionKey(String sessionKey) {
        this.sessionKey = sessionKey;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
